package cn.wizzer.app.user.modules.models;

import cn.wizzer.app.user.modules.models.enums.MsgStatusEnum;
import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.integration.json4excel.annotation.J4EIgnore;

/**
 * 群消息
 */
@Data
@Table("group_log_user_relation")
@TableIndexes({@Index(name = "INDEX_CT_AT", fields = {"ctAt"}, unique = false)})
public class GroupLogUserRelation extends BaseModel {

    @Column
    @Name
    @Comment("ID")
    @J4EIgnore
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @PrevInsert(uu32 = true)
    private String id;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String groupLogId;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String groupId;

    @Column
    @Comment("创建时间")
    @PrevInsert(els = @EL("$me.now()"))
    private Long ctAt;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String userId;

    @Column
    @ColDefine(type = ColType.VARCHAR, width = 16)
    @Comment("状态")
    @Default("UN_READ")
    private MsgStatusEnum status;

    /**
     * 创建用户读取群消息记录
     *
     * @param groupId
     * @param groupLogId
     * @param userId
     * @param status
     * @return
     */
    public static GroupLogUserRelation create(String groupId, String groupLogId, String userId, MsgStatusEnum status) {
        GroupLogUserRelation groupLogUserRelation = new GroupLogUserRelation();
        groupLogUserRelation.setGroupId(groupId);
        groupLogUserRelation.setGroupLogId(groupLogId);
        groupLogUserRelation.setUserId(userId);
        groupLogUserRelation.setStatus(status);
        return groupLogUserRelation;
    }

}
